export default function useMiniUI(miniui?: any) {
  if (!miniui) {
    console.error('Param `miniui` should not be undefined')
  }

  if (['interactive', 'complete'].indexOf(document.readyState) !== -1) {
    // DOMContentLoaded has fired, that means `mini.parse()` has been called.
    return Promise.resolve(miniui)
  } else {
    return new Promise(resolve => {
      document.addEventListener("DOMContentLoaded", () => {
        // put it into macro queue which will be executed in the next round of event loop
        // to avoid the risk of invocation happened before `mini.parse()`
        setTimeout(() => {
          resolve(miniui)
        }, 0)
      })
    })
  }
}
